﻿using System;
using System.Collections;
using System.Collections.Generic;
using com.guojin.mj.net.message.game;
using UnityEngine;
using UnityEngine.UI;

public class ChapterEndItemPage : EventManager
{
    public override void InformationSetting()
    {
    }

    public Text nameTex;
    public GameObject groupObj;
    public Text cardTypeTex;
    public Text scoreTex;
    private int userState;

    public void InitChapterEndItem(UserChapterInfoRet ucir)
    {
        userState = ucir.BetState;
        SetName(GameRoomModel.GetInstance().playerDic[ucir.LocationIndex].userName);
        SetCardGroup(ucir.Cards);
        SetCardType(ucir);
        SetScore(ucir.SettlementScore);
    }

    private void  SetName(string name)
    {
        SetText(nameTex, name);
    }

    private void SetCardGroup(int[] cards)
    {
        for (int i = 0; i < cards.Length; i++)
        {
            if (userState == 5 && i < 2)       //如果是弃牌前两张显示背面  
            {
                groupObj.transform.GetChild(i).GetComponent<ChapterEndCard>().LoadBackSprite();
            }
            else
            {
                groupObj.transform.GetChild(i).GetComponent<ChapterEndCard>().cardValue = cards[i];
                groupObj.transform.GetChild(i).GetComponent<ChapterEndCard>().LoadValueSprite();
            }

            groupObj.transform.GetChild(i).gameObject.SetActive(true);
        }
    }

    private void SetCardType(UserChapterInfoRet ucir)
    {
        if (userState != 5)
        {
            SetText(cardTypeTex, ucir.CardType);
        }
        else
        {
            SetText(cardTypeTex, "弃牌");
        }
    }

    private void SetScore(int score)
    {
        string  totalScore = score.ToString();

        if (totalScore.Substring(0, 1) == "-")
        {
            SetText(scoreTex, string.Format("<color=red>{0}</color>", totalScore));
        }
        else
        {
            SetText(scoreTex, string.Format("<color=green>+{0}</color>", totalScore));
        }
    }
}
